package Node;

import java.io.IOException;
import java.net.Socket;
import java.util.Random;

import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransportException;
import org.ini4j.Ini;

public class TransportLayerServer extends TServerSocket{

	
	private Ini serviceConfig;
	
	/**
	* Creates a new unconnected socket that will connect to the given host
	* on the given port.
	*
	* @param host Remote host
	* @param port Remote port
	 * @throws TTransportException 
	*/
	public TransportLayerServer(int port, Ini serviceConfig) throws TTransportException {
		super(port);
		
		this.serviceConfig = serviceConfig;

	}
	

	
	@Override
	protected TSocket acceptImpl() throws TTransportException {
	    if (this.getServerSocket() == null) {
	      throw new TTransportException(TTransportException.NOT_OPEN, "No underlying server socket.");
	    }
	    try {
	      Socket result = this.getServerSocket().accept();
	      TransportLayer result2 = new TransportLayer(result, serviceConfig);
	      result2.setTimeout(0);
	      return result2;
	    } catch (IOException iox) {
	      throw new TTransportException(iox);
	    }
	  }
	

}
